﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

namespace MESWebService
{
    public class XMLParse
    {
        //将字符串生成XmlDocument对象
        public static XmlDocument getDocument(String xml)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            return doc;
        }
        public static XmlDocument loadDocument(String filePath)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(filePath);
            return doc;
        }
        //获取节点集合
        public static XmlNodeList getNodeList(XmlDocument document, string nodeXPath)
        {
            XmlElement root = document.DocumentElement;
            return root.SelectNodes(nodeXPath);
        }

        //获取单一节点
        public static XmlNode getNode(XmlDocument document, string nodeXPath)
        {
            XmlElement root = document.DocumentElement;
            return root.SelectSingleNode(nodeXPath);
        }

        //获取单一节点
        public static XmlElement getElement(XmlDocument document, string nodeXPath)
        {
            XmlElement root = document.DocumentElement;
            return (XmlElement)root.SelectSingleNode(nodeXPath);
        }
    }
}